<?php

class Form_HmsEditForm extends Form_ViewForm {
	
	private $_setupFields = array('maxlength', 'required', 'help', 'optionsArray', 'label', 'additionalArray');
	
	public function __construct($arrSettings = null, ActiveRecord $objAR = null) {
		parent::__construct($arrSettings, $objAR);
		
		$this->_setupFields = array_combine($this->_setupFields, array_fill(0, count($this->_setupFields), ''));
		echo '<div class="info" data-id="' . $this->_objAR->id . '">';
	}
	
	public function __destruct() {
		echo '<div class="clear"></div></div>';
	}
	
	final protected function drawHTML(array &$arrSettings = array(), $fieldName = null, $type = 'single-line') {
		if(!array_key_exists($fieldName, $this->_objAR->tableFields)) return;

		$title = $arrSettings['text'];
		$setup = array_intersect_key($arrSettings, $this->_setupFields);
		
		$val = array_key_exists('value', $arrSettings) ? $arrSettings['value'] : $this->_objAR->tableFields[$fieldName];
		?>
		<div class="info-value <?php echo $type?>-type" data-name="<?php echo $fieldName?>" data-description='<?php echo htmlspecialchars(json_encode($setup, JSON_HEX_QUOT | JSON_HEX_APOS), ENT_NOQUOTES)?>'>
			<h4><?php echo $title?></h4>
			<div>
				<div class="value-container"><?php echo $val?></div>
			</div>
		</div>
		<?php
	}
	
	final public function showBeforeField(array $arrSettings = array(), $fieldName = null) {
		$title = $arrSettings['text'];
		?>
		<div class="info-value dummy-type">
			<h4><?php echo $title?></h4>
		</div>
		<?php 
	}
	
	final public function showAfterField(array $arrSettings = array(), $fieldName = null) {
		
	}
	
	final public function checkbox(array $arrSettings = array(), $fieldName = null, $onlyField = false) {
		$arrSettings['text'] = '';
		$this->drawHTML($arrSettings, $fieldName, 'checkbox');
	}
	
	final public function textField(array $arrSettings = array(), $fieldName = null, $onlyField = false) {
		$this->drawHTML($arrSettings, $fieldName);
	}
	
	final public function textareaField(array $arrSettings = array(), $fieldName = null, $onlyField = false) {
		$this->drawHTML($arrSettings, $fieldName, 'multi-line');
	}
	
	final public function selectTimeField(array $arrSettings = array(), $fieldName = null, $onlyField = false) {
		$this->drawHTML($arrSettings, $fieldName, 'time');
	}	
	
	final public function latLng(array $arrSettings = array(), $fieldName = null) {
		$this->drawHTML($arrSettings, $fieldName, 'latlng');
	}
	
	final public function selectField(array $arrSettings = array(), $fieldName = null, $onlyField = false) {
		$this->drawHTML($arrSettings, $fieldName, 'select');
	}
	
	public function submitButton(array $arrSettings = array(), $fieldName = null, $onlyField = false) {
	}
	
	final public function show($justPlain = false) {
	}
	
	final public function close($justPlain = false) {
	}
	
}